﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Boggle.Dictionaries.Aonaware;

namespace Boggle.Dictionaries
{
	public class AonaDictionary : IBoggleDictionary
	{
		#region IBoggleDictionary Members

        public String Name
        {
            get { return "Aona Service Dictionary"; }
        }

        public String Description
        {
            get { return "A dictionary that uses the Aona dictionary service to lookup definitions."; }
        }

        public bool IsDefineSupported
        {
            get { return true; }
        }

        public bool IsWord(string word)
        {
            var defs = Define(word);
            return defs != null && defs.Count > 0;
        }

		public List<string> Define(string word)
		{
			if (String.IsNullOrEmpty(word))
			{
				return new List<string>(0);
			}

			using (DictServiceSoapClient dictService = new DictServiceSoapClient())
			{
				WordDefinition wordDefinition = dictService.DefineInDict("wn", word);
				
				List<string> defs = new List<string>(wordDefinition.Definitions.Length);
				
				foreach (Definition def in wordDefinition.Definitions)
				{
					defs.Add(def.WordDefinition);
				}

				return defs;
			}
		}

		#endregion
    }
}
